<?php
namespace Admin\Model;
//角色模型

class AttributeModel extends CommonModel{
	//自定义字段
    protected $fields =array('id','attr_name','type_id','attr_type','attr_input_type','attr_value');
    //自定义规则
    protected $_validate =array (
        array('attr_name','require','属性名称必须填写'),
        array('type_id','require','属性名称必须填写'),
        array('attr_type','1,2','属性类型只能单选或者唯一',1,'in'),
        array('attr_input_type','1,2','属性录入方法只能为手工或者列表',1,'in'),
    );

    public function listData(){
        //定义页尺寸
        $pagesize = 3;
        //计算数据总数
        $count = $this->count();
        //生成分页导航信息
        $page = new \Think\Page($count,$pagesize);
        $show=$page->show();
        //接收当前所在的页码
        $p = intval(I('get.p'));
        $list=$this->page($p,$pagesize)->select();
        //实现将type_id转换为具体的类型名称信息
        $type = D('Type')->select();
        foreach($type as $key=>$value){
            $typeinfo[$value['id']]=$value;

        }
        //dump($typeinfo);die;
        return array('pageStr'=>$show,'list'=>$list);
    }

    public function remove($attr_id){
        return $this->where(array('id'=>$attr_id))->delete();
    }
}
